/**
 * Created by 居胜 on 2016/5/20.
 */
(function () {
    var $ = function (id) {
        return document.getElementById(id);
    }

    var bindEvent = function (ele, event_name, func) {
        if(ele.addEventListener){
            event_name = event_name.replace(/^on/, "");
            ele.addEventListener(event_name, func, false);
        }else if(ele.attachEvent){
            ele.attachEvent(event_name, func);
        }else{
            ele[event_name] = func;
        }
    }

    var root = $("root");
    bindEvent(root, "onclick", function (event) {
        if(event.target.nodeName == "SPAN"){
            var targetLi = event.target.parentNode;
            liClicked(targetLi);

            //morePic
            var morePic = event.target.className.indexOf("more");
            if(morePic >= 0){
                event.target.setAttribute("class", "");
            }else{
                event.target.setAttribute("class","more");
            }
        }

    })

    function liClicked(liNode) {
        var children = liNode.getElementsByTagName("ul");
        if(children.length > 0){
            var firstUl = children.item(0);
            var display = firstUl.style.display;
            var morePic = firstUl.className;
            if(display === "none"){
                firstUl.style.display = "";
            }else{
                firstUl.style.display = "none";
            }
        }
    }
})();